<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- 第一步： import CSS -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
</head>
<body>
<div id="app">

    <!--el-table:表格组件
    :data：数据绑定  :（v-bind）
    prop="date"：必须跟返回的数据名称保持一致
    -->
    <el-table
            :data="tableData.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase()))"
            style="width: 100%">
        <el-table-column
                label="Date"
                prop="date">
        </el-table-column>
        <el-table-column
                label="Name"
                prop="name">
        </el-table-column>
        <el-table-column
                align="right">
            <template slot="header" slot-scope="scope">
                <el-input
                        v-model="search"
                        size="mini"
                        placeholder="输入关键字搜索"/>
            </template>
            <template slot-scope="scope">
                <el-button
                        size="mini"
                        @click="handleEdit(scope.$index, scope.row)">Edit
                </el-button>
                <el-button
                        size="mini"
                        type="danger"
                        @click="handleDelete(scope.$index, scope.row)">Delete
                </el-button>
            </template>
        </el-table-column>
    </el-table>

    <!--分页组件
    size-change：每页条数
    current-change:当前页码
    current-page:默认当前页码
    page-sizes:页码列表
    page-size:默认显示多少条数
    total：总记录数 后台查询返回的结果
    -->
    <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage1"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="30"
            layout="total, sizes, prev, pager, next, jumper"
            :total="400">
    </el-pagination>


</div>
</body>
<script>
    new Vue({
        el: '#app',
        //js 5语法   js6:data(){}
        data() {
            return {
                tableData: [{
                    date: '2016-05-02',
                    name: '王小虎',
                    address: '上海市普陀区金沙江路 1518 弄'
                }, {
                    date: '2016-05-04',
                    name: '王小虎',
                    address: '上海市普陀区金沙江路 1517 弄'
                }, {
                    date: '2016-05-01',
                    name: '王小虎',
                    address: '上海市普陀区金沙江路 1519 弄'
                }, {
                    date: '2016-05-03',
                    name: '王小虎',
                    address: '上海市普陀区金沙江路 1516 弄'
                }],
                search: '',
                currentPage1: 1,
                currentPage2: 5,
                currentPage3: 5,
                currentPage4: 4
            }
        },
        methods: {
            handleEdit(index, row) {alert(JSON.stringify(row)); //将对象转字符串
                console.log(index, row);
            },
            handleDelete(index, row) {
                console.log(index, row);
            },
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
            }
        },
    })
</script>
</html>